<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>存储器应用实验 :: 计算机组成原理实验指导</title>
    <link rel="prev" href="mem-ram.html">
    <link rel="next" href="mem-path-2.html">
    <meta name="generator" content="Antora 3.2.0-alpha.8">
    <link rel="stylesheet" href="../../_/css/site.css">
<!--    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> -->
  </head>
  <body class="article">
<header class="header">
  <nav class="navbar">
    <div class="navbar-brand">
      <a class="navbar-item" href="../..">计算机组成原理实验指导</a>
      <button class="navbar-burger" aria-controls="topbar-nav" aria-expanded="false" aria-label="Toggle main menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
    </div>
    <div id="topbar-nav" class="navbar-menu">
      <div class="navbar-end">

        <div class="navbar-item">
          <span class="control">
            <a class="button is-primary" href="https://gitee.com/fpga-lab/digisimlab-open" target="_blank">Download</a>
          </span>
        </div>
      </div>
    </div>
  </nav>
</header>
<div class="body">
<div class="nav-container" data-component="digisimlab" data-version="">
  <aside class="nav">
    <div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
  <nav class="nav-menu">
    <button class="nav-menu-toggle" aria-label="Toggle expand/collapse all" style="display: none"></button>
    <h3 class="title"><a href="../index.html">计算机组成原理实验指导</a></h3>
<ul class="nav-list">
  <li class="nav-item" data-depth="0">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">Digital仿真软件使用指南</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../introduce-digitalsim.html">概述</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-getting-started.html">新手入门</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-generate-circuit.html">电路生成</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-test-circuit.html">电路测试</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-sim-dff.html">时序电路仿真</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-other-useful.html">几个有用的组件</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-hierarchical-design.html">层次化设计</a>
  </li>
  <li class="nav-item" data-depth="1">
    <a class="nav-link" href="../ds-parametric-design.html">参数化设计</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">逻辑电路基础</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-multiplexer.html">多路选择器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-decoder.html">译码器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-register.html">触发器和寄存器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="bl-counter.html">计数器实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-register_file.html">寄存器堆实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">运算器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-add_sub_operation.html">加减运算电路实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-arithmetic_logic_unit.html">算术逻辑单元实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="op-compare.html">比较运算电路实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="dp-single_cycle_datapath.html">运算器数据通路实验</a>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">存储器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="mem-rom.html">ROM实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="mem-ram.html">RAM实验</a>
  </li>
  <li class="nav-item is-current-page" data-depth="2">
    <a class="nav-link" href="mem-path.html">存储器应用实验</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="mem-path-2.html">存储器数据通路实验</a>
  </li>
</ul>
  </li>
</ul>
  </li>
  <li class="nav-item" data-depth="0">
<ul class="nav-list">
  <li class="nav-item" data-depth="1">
    <button class="nav-item-toggle"></button>
    <span class="nav-text">控制器</span>
<ul class="nav-list">
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-overview.html">概述（指令系统）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-1.html">硬布线控制实验（RI）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller-3.html">硬布线控制实验（RIM）</a>
  </li>
  <li class="nav-item" data-depth="2">
    <a class="nav-link" href="cu-hardwire_controller.html">硬布线控制实验（RIB）</a>
  </li>
</ul>
  </li>
</ul>
  </li>
</ul>
  </nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
  <div class="context">
    <span class="title">计算机组成原理实验指导</span>
    <span class="version">1.31</span>
  </div>
  <ul class="components">
    <li class="component is-current">
      <div class="title"><a href="../index.html">计算机组成原理实验指导</a></div>
      <ul class="versions">
        <li class="version is-current is-latest">
          <a href="../index.html">1.31</a>
        </li>
        <li class="version">
          <a href="../1.2/index.html">1.2</a>
        </li>
        <li class="version">
          <a href="../1.1/index.html">1.1</a>
        </li>
        <li class="version">
          <a href="../1.0/index.html">1.0</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
    </div>
  </aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
  <a href="../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
  <ul>
    <li><a href="../index.html">计算机组成原理实验指导</a></li>
    <li>存储器</li>
    <li><a href="mem-path.html">存储器应用实验</a></li>
  </ul>
</nav>
<div class="page-versions">
  <button class="version-menu-toggle" title="Show other versions of page">1.31</button>
  <div class="version-menu">
    <a class="version is-current" href="mem-path.html">1.31</a>
    <a class="version" href="../1.2/lab/mem-path.html">1.2</a>
    <a class="version" href="../1.1/lab/mem-path.html">1.1</a>
    <a class="version is-missing" href="../1.0/index.html">1.0</a>
  </div>
</div>
</div>
  <div class="content">
<aside class="toc sidebar" data-title="页内目录" data-levels="2">
  <div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page">存储器应用实验</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>注：本项目与<a href="mem-path-2.html" class="xref page">存储器数据通路</a>实验二选一。</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验目的"><a class="anchor" href="#_实验目的"></a>实验目的</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>熟悉静态随机存取存储器RAM的工作特性和使用方法；</p>
</li>
<li>
<p>熟悉只读存储器ROM的工作特性和使用方法；</p>
</li>
<li>
<p>理解实验电路的操作时序，掌握存储器写入和读出数据的过程。</p>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验原理"><a class="anchor" href="#_实验原理"></a>实验原理</h2>
<div class="sectionbody">
<div class="paragraph">
<p>实验电路如<a href="#fig-mem-path-1">图 1</a>所示。该电路将静态随机存取存储器<a href="mem-ram.html" class="xref page">RAM</a>、只读存储器<a href="mem-rom.html" class="xref page">ROM</a>和<a href="dp-register_file.html" class="xref page">三端口寄存器堆</a>组织到一起，构成了一个应用电路。</p>
</div>
<div id="fig-mem-path-1" class="imageblock">
<div class="content">
<img src="_images/mem-path1-1.png" alt="mem path1 1">
</div>
<div class="title">图 1. 存储器应用原理图</div>
</div>
<div class="paragraph">
<p>该电路可以将外部数据存入寄存器堆，以及在RAM和寄存器堆之间相互传递数据，下面从几个方面阐述工作原理。</p>
</div>
<div class="sect2">
<h3 id="_ram存储器地址的产生"><a class="anchor" href="#_ram存储器地址的产生"></a>RAM存储器地址的产生</h3>
<div class="paragraph">
<p>要对RAM读或写，必须要指定读写的RAM单元地址。
从<a href="#fig-mem-path-1">图 1</a>可知，RAM的地址A来自加法器的输出S，因此只能通过加法运算产生RAM地址。而加法的运算数据分别来自寄存器堆的RD1和立即数Imm，所以只能用RD1加上立即数来指定RAM的地址。从<a href="dp-register_file.html" class="xref page">寄存器堆实验</a>可知，RD1即RA1指定的寄存器的值。即</p>
</div>
<div class="paragraph text-center">
<p>A = RD1 + Imm = R[RA1] + Imm</p>
</div>
<div class="paragraph">
<p>式中，R[n]表示编号为n的寄存器的值。</p>
</div>
<div class="paragraph">
<p>生成地址的信息路径如<a href="#fig-mem-path1-2">图 2</a>红线所示。</p>
</div>
<div id="fig-mem-path1-2" class="imageblock">
<div class="content">
<img src="_images/mem-path1-2.png" alt="mem path1 2" width="600">
</div>
<div class="title">图 2. 存储器地址生成的信息路径</div>
</div>
<div class="paragraph">
<p>特别地，如果RA1=0，即RD1为R0寄存器的值；根据<a href="dp-register_file.html" class="xref page">寄存器堆实验</a>的设计，R0寄存器的值恒为0，则</p>
</div>
<div class="paragraph text-center">
<p>A = R[0] + Imm = Imm</p>
</div>
<div class="paragraph">
<p>同理，如果外部输入Imm=0，则</p>
</div>
<div class="paragraph text-center">
<p>A = R[RA1]</p>
</div>
</div>
<div class="sect2">
<h3 id="bm-reg-mem"><a class="anchor" href="#bm-reg-mem"></a>寄存器数据写入RAM</h3>
<div class="paragraph">
<p>要将数据写入RAM，不仅要提供RAM地址，还需提供要写入的数据。
RAM的数据输入DI来自寄存器堆的读端口2，所以只能将某一寄存器的值写入RAM的存储单元。即</p>
</div>
<div class="paragraph text-center">
<p>DI = RD2 = R[RA2]</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="注"></i>
</td>
<td class="content">
关于如何将外部数据存入寄存器堆，见后面<a href="#bm-mem-path1-5">常数存入寄存器</a>。
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>数据信息传递路径如<a href="#fig-mem-path1-3">图 3</a>绿线所示。</p>
</div>
<div id="fig-mem-path1-3" class="imageblock">
<div class="content">
<img src="_images/mem-path1-3.png" alt="mem path1 3" width="600">
</div>
<div class="title">图 3. 寄存器数据写入RAM的数据传递路径</div>
</div>
<div class="paragraph">
<p>准备好地址和数据后，便可使用<a href="mem-ram.html" class="xref page">RAM实验</a>中学习的方法写入存储器。</p>
</div>
</div>
<div class="sect2">
<h3 id="_ram数据写入寄存器堆"><a class="anchor" href="#_ram数据写入寄存器堆"></a>RAM数据写入寄存器堆</h3>
<div class="paragraph">
<p>从RAM读出的数据通过DO端口输出，要将DO数据传送到寄存器堆的写端口WD，中间还经过了一个多路选择器，DO与多路器的输入通道1连接。
WDs是该多路器的选择信号，同时它也是RAM的输出使能控制信号。当WDs=1时，允许RAM输出数据，同时多路器选择通道1，将DO传递到WD。即</p>
</div>
<div class="paragraph text-center">
<p>当WDs=1，WD = DO = RAM[A]</p>
</div>
<div class="paragraph">
<p>式中，RAM[A]表示以A为地址的RAM单元内容。</p>
</div>
<div class="paragraph">
<p>数据信息传递路径如<a href="#fig-mem-path1-4">图 4</a>绿线所示。</p>
</div>
<div id="fig-mem-path1-4" class="imageblock">
<div class="content">
<img src="_images/mem-path1-4.png" alt="mem path1 4" width="600">
</div>
<div class="title">图 4. RAM数据写入寄存器的数据传递路径</div>
</div>
<div class="paragraph">
<p>从RAM读出的数据到达WD端口后，根据<a href="dp-register_file.html" class="xref page">寄存器堆实验</a>中学过方法，可将数据写入寄存器堆中的某个寄存器。</p>
</div>
</div>
<div class="sect2">
<h3 id="bm-mem-path1-5"><a class="anchor" href="#bm-mem-path1-5"></a>常数存入寄存器</h3>
<div class="paragraph">
<p>从前面<a href="#bm-reg-mem">寄存器数据写入RAM</a>已经知道，写入RAM的数据只能来自于寄存器堆，也就是说，需要写入RAM的数据必须事先存放于某一寄存器中。</p>
</div>
<div id="fig-mem-path1-5" class="imageblock">
<div class="content">
<img src="_images/mem-path1-5.png" alt="mem path1 5" width="600">
</div>
<div class="title">图 5. 常数写入寄存器的信息传递路径</div>
</div>
<div class="paragraph">
<p>如<a href="#fig-mem-path1-5">图 5</a>所示。
要写入寄存器的常数通过Imm输入引脚送入。
Imm送到了加法器的B输入端，所以要将Imm送到寄存器堆的写端口，首先要经过加法器的运算。
在前面<a href="dp-register_file.html" class="xref page">寄存器堆实验</a>中已经设计R0寄存器的值恒为0，可以用加法器将Imm加上R0寄存器值，就能够将Imm传送到加法器的输出端S。即</p>
</div>
<div class="paragraph text-center">
<p>当RA1=0，S = R[0] + Imm = Imm</p>
</div>
<div class="paragraph">
<p>从加法器的输出S到寄存器堆的写端口WD，还要经过一个多路选择器，S与多路器的输入通道0连接。
当WDs=0时，多路器选择通道0，将S传递到WD。即</p>
</div>
<div class="paragraph text-center">
<p>当WDs=0 且 RA1=0，WD = S = Imm</p>
</div>
<div class="paragraph">
<p>Imm给出的常数到达WD端口后，根据<a href="dp-register_file.html" class="xref page">寄存器堆实验</a>学过的方法，可将常数存入寄存器堆中的某个寄存器。</p>
</div>
</div>
<div class="sect2">
<h3 id="_rom实现七段显示译码"><a class="anchor" href="#_rom实现七段显示译码"></a>ROM实现七段显示译码</h3>
<div class="paragraph">
<p>在<a href="mem-rom.html" class="xref page">ROM实验</a>中已经学习了用ROM设计七段显示译码电路，<a href="#fig-mem-path-1">图 1</a>用于将WD显示在数码管上。</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_实验任务"><a class="anchor" href="#_实验任务"></a>实验任务</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_设计任务"><a class="anchor" href="#_设计任务"></a>设计任务</h3>
<div class="paragraph">
<p>按照<a href="#fig-mem-path-1">图 1</a>绘制电路图。
其中ROM充当了七段译码器，其容量为16×8位，需初始化其数据为七段译码。
RAM容量为16×4位；寄存器堆为4×4位，其中R0恒为0；加法器组件的数据位数为4位。</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="提示"></i>
</td>
<td class="content">
<div class="paragraph">
<p>ROM和数码管电路可以直接复制<a href="mem-rom.html" class="xref page">ROM实验</a>中已经完成的电路。</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="_验证任务"><a class="anchor" href="#_验证任务"></a>验证任务</h3>
<div class="paragraph">
<p>依次完成以下验证任务，分析实验数据，判断结果的正确性。
若结果与预期不符，尝试分析故障现象并排除故障，提升分析问题与解决问题的能力。
最后保存仿真过程数据文件。</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>常数写入寄存器堆</p>
<div class="paragraph">
<p>从前面实验原理可知，RAM的地址需要寄存器参与运算后产生，写入RAM的数据也是来自寄存器堆。所以首先将2个不同的非零常数分别存入2个寄存器。</p>
</div>
</li>
<li>
<p>寄存器数据写入RAM</p>
<div class="paragraph">
<p>将前面已存入数据的2个寄存器的内容，一个与Imm相加作为RAM地址，另一个作为写入RAM的数据，完成RAM的写操作。</p>
</div>
</li>
<li>
<p>读出RAM数据并写入寄存器堆</p>
<div class="paragraph">
<p>将上面已经存入RAM的数据读出并写入空闲的其他寄存器。</p>
</div>
</li>
</ol>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="提示"></i>
</td>
<td class="content">
分析结果时还应检查ROM输出的七段数据和数码管显示是否正确。
</td>
</tr>
</table>
</div>
<div class="sidebarblock text-center">
<div class="content">
<div class="title">许可 | License</div>
<div class="paragraph">
<p><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA：署名-非商业性使用-相同方式共享 4.0 国际许可协议</a></p>
</div>
<div class="paragraph">
<p>作者：
肖铁军 &lt;<a href="mailto:xiaotiejun@foxmail.com.cn">xiaotiejun@foxmail.com.cn</a>&gt;</p>
</div>
</div>
</div>
</div>
</div>
</div>
<nav class="pagination">
  <span class="prev"><a href="mem-ram.html">RAM实验</a></span>
  <span class="next"><a href="mem-path-2.html">存储器数据通路实验</a></span>
</nav>
</article>
  </div>
</main>
</div>
<footer class="footer">
  <p>This page was built using the Antora default UI.</p>
  <p>The source code for this UI is licensed under the terms of the MPL-2.0 license.</p>
</footer>
<script id="site-script" src="../../_/js/site.js" data-ui-root-path="../../_"></script>
<script async src="../../_/js/vendor/highlight.js"></script>
  </body>
</html>
